package com.hyphenate.easeui.chat;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;

import com.e.library.http.EApi;
import com.e.library.http.EClient;
import com.e.library.http.EObserver;
import com.e.library.http.EResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * 保存聊天记录
 * @author lxy
 * @time 2017/8/16  15:24
 */
public class ChatService extends IntentService {

    public static final String ID = "to_id";
    public static final String CONTENT = "content";

    public static void chat(Context context,String id,String content){
        Intent intent = new Intent(context,ChatService.class);
        intent.putExtra(ID,id);
        intent.putExtra(CONTENT,content);
        context.startService(intent);
    }

    public ChatService() {
        super("ChatService");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {

        String to_id = intent.getStringExtra(ID);
        String content = intent.getStringExtra(CONTENT);

        Map<String,String> params = new HashMap<>(2);
        params.put(ID,to_id);
        params.put(CONTENT,content);
        EClient.with().post(EApi.CHAT_SAVE, params, new EObserver() {
            @Override
            public void successful(EResponse response) {
            }

            @Override
            public void failure(String msg) {

            }
        });
    }
}
